// 项目的 JS 入口文件
var path = require('path')
var webpack = require('webpack')
var htmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js'
    },
    mode: 'development',
    devServer: {
        open: true,
        port: 3000,
        // contentBase: 'src',
        hot: true,
        disableHostCheck: true
    },
    plugins: [
        new htmlWebpackPlugin({
            template: path.join(__dirname, './src/index.html'),
            filename: 'index.html'
        }),
        new VueLoaderPlugin(),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            'window.$':'jquery',
            'window.jQuery':'jquery'
        })
    ],
    module: {
        rules: [
            { test:/\.css$/, use: ['style-loader', 'css-loader'] },
            { test:/\.less$/, use: ['style-loader', 'css-loader', 'less-loader'] },
            { test:/\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
            { test:/\.(jpg|png|jpeg|gif|bmp)$/, use: 'url-loader' },
            { test:/\.(eot|svg|ttf|woff|woff2)$/, use: 'url-loader' },
            { test:/\.vue$/, use: 'vue-loader' },
            { 
                test:/\.js$/, 
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader', 
                    options:{ 
                        presets: ['@babel/preset-env'],
                        plugins: [
                            '@babel/plugin-transform-runtime',
                            '@babel/plugin-proposal-class-properties'
                        ]
                    } 
                }
            }
        ]
    },
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.min.js'
        }
    }
}